package com.zjw.zy.utils.taskpool;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;

import java.util.concurrent.Executor;

/**
 * 绘图线程
 */
public class GraphicExecutor implements Executor {

    private final HandlerThread mGraphicHandlerThread = new HandlerThread("Graphic-Thread");
    private final Handler mHandler;

    private static final class GraphicExecutorHolder {
        public static final GraphicExecutor INSTANCE = new GraphicExecutor();
    }

    public static GraphicExecutor get() {
        return GraphicExecutorHolder.INSTANCE;
    }

    private GraphicExecutor() {
        mGraphicHandlerThread.start();
        mHandler = new Handler(mGraphicHandlerThread.getLooper());
    }

    public Looper getLooper() {
        return mGraphicHandlerThread.getLooper();
    }

    @Override
    public void execute(Runnable command) {
        mHandler.post(command);
    }
}